﻿using RTW.Core.Ioc;
using RTW.Core.Repository;
using RTW.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RTW.Servers
{
    public class UnitServers : BaseServers<SysUnit>, IAutoInject
    {
        private readonly IRepositoryAsync<SysUnit> SysUnitRepository;
        public UnitServers()
        {
            SysUnitRepository = new DapperAsyncRepository<SysUnit>();
        }


        public async Task<List<SysUnit>> GetAllUnits()
        {
            return (await SysUnitRepository.GetAllEnumerableAsync()).ToList();
        }

        public async Task<SysUnit> GetUnit(int? id)
        {
            return await SysUnitRepository.GetByIdAsync(id);
        }


        public async Task<bool> AnyByName(object name)
        {
            return await SysUnitRepository.SqlWithParamsBool("select * from Sys_Unit  where DWMC=:DWMC",new { DWMC = name });
        }

        public async Task<bool> AnyByCode(string code)
        {
            return await SysUnitRepository.SqlWithParamsBool("select * from Sys_Unit  where DWDM=:DWDM", new { DWDM = code });
        }
    }
}
